package day17;

public class ThreadTicketPractice {
    public static void main(String[] args) {
        ticketPrc1 tPrc1 = new ticketPrc1("阿龙");
        ticketPrc1 tPrc2 = new ticketPrc1("阿飞");
        ticketPrc1 tPrc3 = new ticketPrc1("阿勇");
        ticketPrc1 tPrc4 = new ticketPrc1("阿彪");
        tPrc1.start();
        tPrc2.start();
        tPrc3.start();
        tPrc4.start();
    }
}
class ticketPrc1 extends Thread{
    static int tickets=100;
    public ticketPrc1() {
    }

    public ticketPrc1(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (true){
            synchronized (ThreadTicketPractice.class){
                try {
                    sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (tickets>0)
                    System.out.println(getName()+","+tickets--);
                if (tickets<=0)break;
            }

        }
    }
}